﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_offer
	/// </summary>
	public partial class enterprise_offer
	{
		public enterprise_offer()
		{}

        /// <summary>
        /// 批量个更改
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="value">更改值</param>
        /// <param name="where">更改条件enterprise_rid</param>
        /// <returns></returns>
        public bool UpdateWhere(string keywords, string value, string where)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update enterprise_offer set " + keywords + " = '" + value + "' ");
            strSql.Append(" where enterprise_oid in (" + where + ")  ");

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_oid", "enterprise_offer"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_oid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_oid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_oid;

			int result= DbHelperSQL.RunProcedure("enterprise_offer_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.enterprise_offer model)
		{
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_oid", SqlDbType.Int,4),
					new SqlParameter("@introducername", SqlDbType.NVarChar,12),
					new SqlParameter("@enterprise_reward_id", SqlDbType.Int,4),
					new SqlParameter("@infoperson", SqlDbType.Text),
					new SqlParameter("@introducerid", SqlDbType.VarChar,50),
					new SqlParameter("@mobilphone", SqlDbType.Char,11),
					new SqlParameter("@email", SqlDbType.VarChar,30),
					new SqlParameter("@otime", SqlDbType.DateTime),
					new SqlParameter("@status", SqlDbType.SmallInt,2)};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.introducername;
            parameters[2].Value = model.enterprise_reward_id;
            parameters[3].Value = model.infoperson;
            parameters[4].Value = model.introducerid;
            parameters[5].Value = model.mobilphone;
            parameters[6].Value = model.email;
            parameters[7].Value = model.otime;
            parameters[8].Value = model.status;

            DbHelperSQL.RunProcedure("enterprise_offer_ADD", parameters, out rowsAffected);
            return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_offer model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_oid", SqlDbType.Int,4),
					new SqlParameter("@introducername", SqlDbType.NVarChar,6),
					new SqlParameter("@enterprise_reward_id", SqlDbType.Int,4),
					new SqlParameter("@infoperson", SqlDbType.Text),
					new SqlParameter("@introducerid", SqlDbType.VarChar,50),
					new SqlParameter("@mobilphone", SqlDbType.Char,11),
					new SqlParameter("@email", SqlDbType.VarChar,30)};
			parameters[0].Value = model.enterprise_oid;
			parameters[1].Value = model.introducername;
			parameters[2].Value = model.enterprise_reward_id;
			parameters[3].Value = model.infoperson;
			parameters[4].Value = model.introducerid;
			parameters[5].Value = model.mobilphone;
			parameters[6].Value = model.email;

			DbHelperSQL.RunProcedure("enterprise_offer_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_oid)
		{
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from enterprise_offer ");
            strSql.Append(" where enterprise_oid=@enterprise_oid");

            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_oid", SqlDbType.Int,4)
};
            parameters[0].Value = enterprise_oid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
			
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_oidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from enterprise_offer ");
			strSql.Append(" where enterprise_oid in ("+enterprise_oidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public lcmyjobs.Model.enterprise_offer GetModel(int enterprise_oid)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_oid", SqlDbType.Int,4)};
            parameters[0].Value = enterprise_oid;

            lcmyjobs.Model.enterprise_offer model = new lcmyjobs.Model.enterprise_offer();
            DataSet ds = DbHelperSQL.Query(" select * from enterprise_offer where enterprise_oid=@enterprise_oid ",parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["enterprise_oid"].ToString() != "")
                {
                    model.enterprise_oid = int.Parse(ds.Tables[0].Rows[0]["enterprise_oid"].ToString());
                }
                model.introducername = ds.Tables[0].Rows[0]["introducername"].ToString();
                if (ds.Tables[0].Rows[0]["enterprise_reward_id"].ToString() != "")
                {
                    model.enterprise_reward_id = int.Parse(ds.Tables[0].Rows[0]["enterprise_reward_id"].ToString());
                }
                model.infoperson = ds.Tables[0].Rows[0]["infoperson"].ToString();
                model.introducerid = ds.Tables[0].Rows[0]["introducerid"].ToString();
                model.mobilphone = ds.Tables[0].Rows[0]["mobilphone"].ToString();
                model.email = ds.Tables[0].Rows[0]["email"].ToString();
                if (ds.Tables[0].Rows[0]["otime"].ToString() != "")
                {
                    model.otime = DateTime.Parse(ds.Tables[0].Rows[0]["otime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_oid,introducername,enterprise_reward_id,infoperson,introducerid,mobilphone,email ");
			strSql.Append(" FROM enterprise_offer ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_oid,introducername,enterprise_reward_id,infoperson,introducerid,mobilphone,email ");
			strSql.Append(" FROM enterprise_offer ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_offer";
			parameters[1].Value = "enterprise_oid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

